package com.itheima.a01Functioalm;

import java.util.ArrayList;
import java.util.Collections;
import java.util.function.Predicate;

public class a01Funcionaldemo1 {
    public static void main(String[] args) {
        //创建集合
        /*
        "张无忌","周芷若","赵敏","张强","张三丰"
         */
        ArrayList<String> list =new ArrayList<>();
        //添加数据
        Collections.addAll(list,"张无忌","周芷若","赵敏","张强","张三丰");
        //只留下姓张且名字为三个字的人
//        list.stream().filter(s->s.startsWith("张"))
//                .filter(s->s.length()==3)
//                .forEach(s-> System.out.println(s));

        //使用方法引用
//        list.stream().filter(new Predicate<String>() {
//            @Override
//            public boolean test(String s) {
//                boolean result = s.startsWith("张") && s.length() == 3;
//                return result;
//            }
//        }).forEach(s-> System.out.println(s));

        //进行改写
        //new StringOperation();
//        list.stream().filter(new StringOperation() :: StringGudge)
//                .forEach(s-> System.out.println(s));

        //在静态方法中没有this关键字  需要创建本类的对象
        list.stream().filter(new a01Funcionaldemo1() :: StringGudge)
                .forEach(s-> System.out.println(s));
        }

    public boolean StringGudge(String s){
        boolean result = s.startsWith("张") && s.length() == 3;
        return result;
    }
}
